#include"../../commom/message.hpp"
#include"../../commom/net.hpp"
#include"../../commom/dispatcher.hpp"
#include <unistd.h>
void onRpcResponse(const rpc::BaseConnection::ptr &conn,const rpc::BaseMessage::ptr &msg)
{
    std::cout<<"收到了rpc响应"<<std::endl;
    std::string s=msg->serialize();
    std::cout<<s<<std::endl;
}
int main()
{
    auto dispatcher=std::make_shared<rpc::Dispatcher>();
    dispatcher->registerHandler<rpc::RpcResponse>(rpc::MType::RSP_RPC,onRpcResponse);
    auto client=rpc::ClientFactory::create("127.0.0.1",8080);
    auto message_cb=std::bind(&rpc::Dispatcher::onMessage,dispatcher.get(),
            std::placeholders::_1,std::placeholders::_2);       
    client->setMessageCallback(message_cb);
    client->connect();
    auto rpc_req=rpc::MessageFactory::create<rpc::RpcRequest>();
    rpc_req->setId("11111");
    rpc_req->setMType(rpc::MType::REQ_RPC);
    rpc_req->setMethod("Add");
    Json::Value para;
    para["num1"]=11;
    para["num2"]=22;
    rpc_req->setPara(para);
    client->send(rpc_req);
    sleep(30);
    client->shutdown();

}
